import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @author: Themberfue
 * @date: 2025/4/5 10:52
 * @description:
 */
public class RedisSet {
    public static void main(String[] args) {
        try (JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
            Jedis jedis = jedisPool.getResource()) {
                sinterAndSinterstore(jedis);
        }
    }

    private static void sinterAndSinterstore(Jedis jedis) {
        jedis.flushAll();

        jedis.sadd("k1", "111", "222", "333");
        jedis.sadd("k2", "111", "222", "444");

        Set<String> sinterRes = jedis.sinter("k1", "k2");
        System.out.println(sinterRes);

        jedis.sinterstore("k3","k1", "k2");
        Set<String> res = jedis.smembers("k3");
        System.out.println(res);
    }

    private static void sismemberAndSpop(Jedis jedis) {
        jedis.flushAll();

        jedis.sadd("k1", "111", "222", "333");

        boolean sismemberRes = jedis.sismember("k1", "111");
        System.out.println(sismemberRes);

        String spopRes = jedis.spop("k1");
        System.out.println(spopRes);

        spopRes = jedis.spop("k1");
        System.out.println(spopRes);

        spopRes = jedis.spop("k1");
        System.out.println(spopRes);

        spopRes = jedis.spop("k1");
        System.out.println(spopRes);
    }

    private static void saddAndSmembersAndScard(Jedis jedis) {
        jedis.flushAll();

        jedis.sadd("k1", "111", "222", "333");

        Set<String> smembersRes = jedis.smembers("k1");
        System.out.println(smembersRes);

        long len = jedis.scard("k1");
        System.out.println(len);
    }

}
